package com.winshare.saleAssistant.controller;

import com.winshare.saleAssistant.domain.dto.req.*;
import com.winshare.saleAssistant.service.ArticleService;
import com.winshare.saleAssistant.util.LogicResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/sys/article")
@CrossOrigin
@Api(value = "文章管理", description = "文章管理")
public class ArticleController {

    private final ArticleService articleService;

    public ArticleController(ArticleService articleService) {
        this.articleService = articleService;
    }

    @PostMapping("/save")
    @ApiOperation(value = "新增文章接口",notes = "新增文章接口")
    public LogicResponse save(@RequestBody @Validated ArticleCreateDTO articleCreateDTO) {
        articleService.save(articleCreateDTO);
        return LogicResponse.success("success");
    }

    @PostMapping("/update")
    @ApiOperation(value = "修改文章接口",notes = "修改文章接口")
    public LogicResponse save(@RequestBody @Validated ArticleUpdateDTO articleUpdateDTO) {
        articleService.update(articleUpdateDTO);
        return LogicResponse.success("success");
    }

    @PostMapping("/detail")
    @ApiOperation(value = "查看文章详情")
    public LogicResponse getArticleDetail(@RequestBody @Validated BaseIdDTO baseIdDTO) {
        return LogicResponse.success(articleService.getArticleDetail(baseIdDTO));
    }

    @PostMapping("/delete")
    @ApiOperation(value = "删除文章接口",notes = "删除文章接口")
    public LogicResponse delete(@RequestBody @Validated ArticleDeleteDTO articleDeleteDTO) {
        articleService.delete(articleDeleteDTO);
        return LogicResponse.success("success");
    }

    @PostMapping("/list")
    @ResponseBody
    @ApiOperation(value = "查询文章列表接口",notes = "查询文章列表接口")
    public LogicResponse queryArticlePage(@RequestBody @Validated ArticleQueryDTO articleQueryDTO) {
        return LogicResponse.success(articleService.getArticleList(articleQueryDTO));
    }

    @PostMapping("/cancel")
    @ApiOperation(value = "文章列表接口",notes = "查询文章列表接口")
    public LogicResponse cancel(@RequestBody @Validated BaseIdDTO articleIdDTO) {
        articleService.cancelArticle(articleIdDTO);
        return LogicResponse.success("success");
    }

    @PostMapping("/preview")
    @ApiOperation(value = "预览文章接口",notes = "预览文章接口")
    public LogicResponse preview(@RequestBody @Validated BaseIdDTO articleIdDTO) {
        return LogicResponse.success(articleService.previewArticle(articleIdDTO));
    }

    @PostMapping("/submit")
    @ApiOperation(value = "文章提交审核接口",notes = "文章提交审核接口")
    public LogicResponse submit(@RequestBody @Validated ArticleIdDTO articleIdDTO) {
        articleService.submitArticle(articleIdDTO);
        return LogicResponse.success("success");
    }

    @PostMapping("/agree")
    @ApiOperation(value = "同意发布文章接口",notes = "同意发布文章接口")
    public LogicResponse agree(@RequestBody @Validated BaseIdDTO articleIdDTO) {
        articleService.agreeIssueArticle(articleIdDTO);
        return LogicResponse.success("success");
    }

//    @PostMapping("/release")
//    @ApiOperation(value = "发布文章接口",notes = "发布文章接口")
//    public LogicResponse release(@RequestBody @Validated BaseIdDTO articleIdDTO) {
//        articleService.releaseIssueArticle(articleIdDTO);
//        return LogicResponse.success("success");
//    }

    @PostMapping("/agree/no")
    @ApiOperation(value = "不同意发布文章接口",notes = "不同意发布文章接口")
    public LogicResponse agreeNo(@RequestBody @Validated BaseIdDTO articleIdDTO) {
        articleService.agreeNoIssueArticle(articleIdDTO);
        return LogicResponse.success("success");
    }

    @PostMapping("/add/readCount")
    @ApiOperation(value = "增加阅读次数，调一次此接口，阅读次数+1",notes = "增加阅读次数，调一次此接口，阅读次数+1")
    public LogicResponse addReadCount(@RequestBody @Validated BaseIdDTO articleIdDTO) {
        articleService.addReadCount(articleIdDTO);
        return LogicResponse.success("success");
    }

    @PostMapping("/add/promotionTimes")
    @ApiOperation(value = "转发一次增加一次推广次数",notes = "转发一次增加一次推广次数")
    public LogicResponse addPromotionTimes(@RequestBody @Validated BaseIdDTO baseIdDTO) {
        articleService.addPromotionTimes(baseIdDTO);
        return LogicResponse.success("success");
    }

}
